package com.yto.hrreport.event.buttons {
	
	import com.yto.hrreport.command.sysTemplatePanel;
	import com.yto.hrreport.event.buttons.superbutton.ButtonEvent;
	
	import mx.containers.Canvas;
	import mx.containers.HDividedBox;
	import mx.controls.Button;
	import mx.controls.Tree;
	
	public class TempCancleButtonEvent extends ButtonEvent {
		
		private static var cancleEvent : TempCancleButtonEvent = new TempCancleButtonEvent();
		private static var parentName : String;
		
		public function TempCancleButtonEvent() {
			
			super();
		}
		
		public static function getInstance(parentName : String) : TempCancleButtonEvent { 
			
			TempCancleButtonEvent.parentName = parentName;
			return cancleEvent;
			
		}
		
		public function cancleEvent(action : String) : void {
			
			var parentCanvas : Canvas = Canvas(hrreport.ui.mainNavigator.getChildByName(parentName + "_canvas"));
			var headCanvas : Canvas = Canvas(parentCanvas.getChildByName(parentName + "_headCanvas"));
			var bodyCanvas : Canvas = Canvas(parentCanvas.getChildByName(parentName + "_bodyCanvas"));
			var hdivBox : HDividedBox = HDividedBox(bodyCanvas.getChildByName(parentName + "_hdivBox"));
			var sysTree : Tree = Tree(hdivBox.getChildByName(parentName + "_sysTree"));
			var template : sysTemplatePanel = sysTemplatePanel.getInstance();
			
			switch(action) {
				
				case "tempAdd" : 
					template.reset();
					sysTree.enabled = true;
					updateButtons(null , "sysTree_ItemChange_template" , headCanvas , false);
					Button(headCanvas.getChildByName(parentName + "_btnAdd")).enabled = true;
					
					break;
				
				case "tempEdit" :
					
					template.reset();
					
					template.headPosGrid.dataProvider = TempEditButtonEvent.getInstance(parentName).getOldHeadPosProvider();
					template.bodyPosGrid.dataProvider = TempEditButtonEvent.getInstance(parentName).getOldBodyPosProvider();
					
					sysTree.enabled = true;
					updateButtons(null , "sysTree_ItemChange_template" , headCanvas , true);
					
					break;
				
				default :
					
					break;
				
			}
			
		}
		
	}
}